import { Button, Col, Form, Input, message, Row, Select } from 'antd';
import React, { useState } from 'react'
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import TextArea from 'antd/lib/input/TextArea';
import FormItem from 'antd/lib/form/FormItem';
import request from '@/http';
const { Option } = Select;

export default function Selects() {

    const onFinish = async (values:any) => {
        await request.post('/api/Topic/TopicCreate?subjectId='+values.state+'&typeId=1',{...values}).then((response:any)=>{
            if(response.code==200){
              message.success(response.message)
            }else{
              message.error(response.message)
            }
            })
      };
      const [SubjectData, setSubjectData] = useState([
        {
          "subjectName": null,
          "id": null
        },]);
      const getSubject=async () => {
          await request.post('/api/Subject/subjectSearch').then((response:any)=>{
            if(response.code==200){
                setSubjectData(response.slists)
            }else{
              message.error(response.message)
            }
            })
      }
      React.useEffect(()=>{
        getSubject();
      },[])
    return (
        <>
            <Form name="dynamic_form_item" onFinish={onFinish}>

            <Row gutter={24}  >
            <Col span={6} key='6'>
                          <Form.Item label="科目" name="state" rules={[
                        { required: true, message: '不能为空!' }
                        ]}>
                              <Select placeholder='请选择'>
                              {SubjectData
                                ? SubjectData.map((item: any, index: any) => {
                                    return (
                                      <Option
                                        index={index}
                                        key={index}
                                        value={item.id}
                                        children={item.subjectName}
                                      />
                                    );
                                  })
                                : ''}
                              </Select>
                            </Form.Item>
                          </Col>
                <Col span={22} key='1'>
                    <FormItem
                        label="题目"
                        name="title"
                        rules={[
                        { required: true, message: '不能为空!' }
                        ]}
                    >
                        <TextArea placeholder="请输入" allowClear />
                    </FormItem>
                </Col>

                <Col span={22} key='2'>
                    <FormItem
                        label="选项"
                        name="options"
                        rules={[
                        { required: true, message: '不能为空!' }
                        ]}
                    >
                        <TextArea placeholder="请输入" allowClear />
                    </FormItem>
                </Col>
                <Col span={10} key='3'>
                    <FormItem
                        label="正确答案"
                        name="trueAnswer"
                        rules={[
                        { required: true, message: '不能为空!' }
                        ]}
                    >
                        <TextArea placeholder="请输入" allowClear />
                    </FormItem>
                </Col>
                <Col span={10} key='5'>
                    <FormItem
                        label="分值"
                        name="score"
                        rules={[
                            { required: true, message: '不能为空!' }
                            ]}
                    >
                        <Input type='number' placeholder="请输入"></Input>
                    </FormItem>
                </Col>
                <Col span={20} key='4'>
                    <Form.Item>
                        <Button type="primary" htmlType="submit">
                        提交
                        </Button>
                    </Form.Item>
                </Col>
            </Row>
        </Form>
        </>
    )
}
